<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>我的服务</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../js/layui/css/layui.css"  media="all">
</head>
<body>
 
<table class="layui-hide" id="test" lay-filter="test"></table>
 
<!-- 头部工具栏 -->
<!-- <script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-normal layui-btn-sm" lam" lay-event="getCheckLength">获取选中数目</button>
    <button class="layui-btn layui-btn-normal layui-btn-sm" layuiy-event="getCheckData">获取选中行数据</button>
    <button class="layui-btn layui-btn-normal layui-btn-s-btn layui-btn-normal layui-btn-sm" lay-event="isAll">验证是否全选</button>
  </div>
</script> -->
 
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="past_medical_history">既往病史</a>
	<a class="layui-btn layui-btn-xs" lay-event="contract">合约详情</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="Rescission">解约</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
              
          
<script src="../js/layui/layui.js" charset="utf-8"></script> 
 
<script>
	var phone = localStorage.getItem("FDSMS");
	layui.use('table', function(){
  var table = layui.table;
  
 table.render({
    elem: '#test'
    ,url:'http://123.56.67.48:8080/getAgLists?phone='+phone//http://homedoc:8881/tp5/public/index.php/Doc/doc/mypatient
		,request: {
		   pageName: 'page' //页码的参数名称，默认：page
		   ,limitName: 'limit' //每页数据量的参数名，默认：limit
		 }
    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
    ,defaultToolbar: ['filter', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
      title: '提示'
      ,layEvent: 'LAYTABLE_TIPS'
      ,icon: 'layui-icon-tips'
    }]
    ,title: '所有签约人信息'
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field:'patName', title:'姓名', width:120,}
      ,{field:'patPhone', title:'联系电话', width:150,}
      ,{field:'address', title:'所在城市', width:150,}
			,{field:'pakName', title:'服务包类型', width:120}
			,{field:'agNum', title:'合约编号', width:120,}
      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:360}
    ]]
    ,page: true
  });
  
  //头工具栏事件
  // table.on('toolbar(test)', function(obj){
  //   var checkStatus = table.checkStatus(obj.config.id);
  //   switch(obj.event){
  //     case 'getCheckData':
  //       var data = checkStatus.data;
  //       layer.alert(JSON.stringify(data));
  //     break;
  //     case 'getCheckLength':
  //       var data = checkStatus.data;
  //       layer.msg('选中了：'+ data.length + ' 个');
  //     break;
  //     case 'isAll':
  //       layer.msg(checkStatus.isAll ? '全选': '未全选');
  //     break;
  //     //自定义头工具栏右侧图标 - 提示
  //     case 'LAYTABLE_TIPS':
  //       layer.alert('家庭医生签约平台管理电话：0825-3366978');
  //     break;
  //   };
  // });
  
  //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
    //console.log(obj)
    if(obj.event === 'del'){
      layer.confirm('真的删除该用户合约吗?', function(index){
				if(data.contract_status == "进行中"){
					layer.msg("合约还在进行中不能删除，你可以先解约！！")
				}
        else{
					obj.del();
					layer.close(index);
				}
      });
    } else if(obj.event === 'contract'){
			// console.log(data);
      layer.open({
      	type: 2,
      	title:"合约详情",
      	area: ['800px', '600px'],
      	content: 'detail_contract.html?phone='+data.patPhone+'&agnum='+data.agNum
      });
    }
  });
});
</script>

</body>
</html>